package edu.neu.cs6515.player.strategy;

import java.util.List;

import edu.neu.cs6515.board.BoardCoord;
import edu.neu.cs6515.board.HexagonBoard;
import edu.neu.cs6515.util.Pair;
import edu.neu.cs6515.xml.Placement;
import edu.neu.cs6515.xml.Score;
import edu.neu.cs6515.xml.Tile;

public class MostSumPointsStrategy extends AbstractStrategy {

    @Override
    public Placement getNextMove(final List<Tile> tilesInHand, final int numberOfPlayers,
            final List<Placement> placementsSofar, final Score scoreBeforePlacement) {

        HexagonBoard hexBoard = new HexagonBoard(numberOfPlayers);
        List<Pair<BoardCoord>> possibleBoardCoords =
                getAllPossiblePlacements(placementsSofar,
                        hexBoard);

        int maxSumOfPoints = 0;
        Placement maxSumPlacement = createPlacement(possibleBoardCoords.get(0),
                tilesInHand.get(0));
        for (Pair<BoardCoord> pair : possibleBoardCoords) {
            for (Tile tile : tilesInHand) {
                Placement p = createPlacement(pair, tile);
                int sumOfPlacement = hexBoard.scoreAMove(p).sumOfAllColors();
                if (maxSumOfPoints < sumOfPlacement) {
                    maxSumOfPoints = sumOfPlacement;
                    maxSumPlacement = p;
                }
            }
        }
        return maxSumPlacement;
    }
}
